package com.example.hibernate.program;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Driver {

	public static void main(String[] args) {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		try {
			Employee employee = new Employee();
			employee.setFirstName("Merve");
			employee.setLastName("ÇİLİNGİROĞLU");
			{
				Address homeAddress = new Address();
				homeAddress.setCity("Istanbul");
				homeAddress.setZipCode("34000");
				employee.setHomeAddress(homeAddress);
			}
			{
				Address workAddress = new Address();
				workAddress.setCity("Ankara");
				workAddress.setZipCode("06");
				employee.setWorkAddress(workAddress);
			}
			session.save(employee);
			
//			Employee employee = (Employee) session.get(Employee.class, 1L);
//			Address address = employee.getAddress();
//			System.out.println(employee);
//			System.out.println(address);
			transaction.commit();
		} catch (Exception e) {
			transaction.rollback();
		}		
		session.close();
		sessionFactory.close();
	}
}
